package tech.kpretty.other;

import java.util.concurrent.CountDownLatch;

public class CountDownLatchDemo {
    public static void main(String[] args) throws InterruptedException {
        // 初始化计数为 6
        CountDownLatch countDownLatch = new CountDownLatch(6);

        for (int i = 0; i < 6; i++) {
            new Thread(() -> {
                System.out.println("消灭了一个国家");
                // 必须放到线程最后，线程完成，计数 -1，计数为0 唤醒主线程
                countDownLatch.countDown();
            }).start();
        }
        // 当计数不等于0，主线程阻塞
        countDownLatch.await();
        System.out.println("秦一统天下...");
    }
}
